public class Leet8 {
    public static void main(String[] args) {
        Leet8 l = new Leet8();
        System.out.println(l.myAtoi("   -42"));
    }
    public int myAtoi(String s) {
        char[] chs = s.toCharArray();
        int fir = 0;
        boolean zf = true;
        for (int i = 0; i < chs.length; i++) {
            if (chs[i]==' ')
                continue;
            else if (isNum(chs[i])){
                fir = i;
                break;
            }else if (isJJ(chs[i])){
                zf = chs[i] == '+';
                if (i!=chs.length-1&&isNum(chs[i+1])){
                    fir = i+1;
                    break;
                }else return 0;
            }else return 0;
        }
        chs = s.substring(fir).toCharArray();
        fir = 0;
        for (int i = 0; i < chs.length; i++) {
            if(!isNum(chs[i])){
                fir = i;
                break;
            }
        }
        System.out.println(s.substring(0,fir));
        System.out.println(fir);
        return 0;
    }
    boolean isNum(char ch){
        return ch >= '0' && ch <= '9';
    }
    boolean isJJ(char ch){
        return ch == '+' || ch == '-';
    }
}
